import Vue from 'vue'
import Router from 'vue-router'
import iview from 'view-design'
// import product from './product'
import setting from './setting'
// import sales from './sales'
// import manage from './manage'
// import welfare from './welfare'
// import policy from './policy'
// import operation from './operation'
// import report from './report'
import order from './order'
import company from './company'
import source from './source'
Vue.use(Router)
Vue.use(iview)

let router = new Router({
  mode: 'history',
  base: '',
  // base: process.env.NODE_ENV === 'development' ? '' : '/yunyi',
  routes: [{
    path: '/',
    name: 'base',
    meta: { id: '1', title: '首页', active: true, icon: 'md-home' },
    component: resolve => require(['@/views/Base'], resolve),
    children: [{
      path: '/home/user/edit',
      name: 'home/user/edit',
      component: resolve => require(['@/views/home/user/UserEdit'], resolve),
      meta: {
        id: '1-1-1',
        title: '账户信息',
        active: false,
        keepAlive: true,
        parent: '账户资料'
      }
    }, {
      path: '/home/platform/list',
      name: 'home/platform/list',
      hidden: false,
      component: resolve => require(['@/views/home/platform/platform'], resolve),
      meta: {
        id: '1-1-2',
        title: '平台信息',
        active: false
      }
    }, {
      path: '/home/tyreJanuary/list',
      name: 'home/tyreJanuary/list',
      hidden: true,
      component: resolve => require(['@/views/home/tyreJanuary/TyreJanuaryList'], resolve),
      meta: {
        id: '1-1-1',
        title: '1-2月抢好胎送豪礼',
        active: false
      }
    }, {
      path: '/home/tyreMarch/list',
      name: 'home/tyreMarch/list',
      hidden: true,
      component: resolve => require(['@/views/home/tyreMarch/TyreMarchList'], resolve),
      meta: {
        id: '1-1-1',
        title: '3-4月抢好胎送福券',
        active: false
      }
    }, {
      path: '/home/tyreApril/list',
      name: 'home/tyreApril/list',
      hidden: true,
      component: resolve => require(['@/views/home/tyreApril/tyreAprilList'], resolve),
      meta: {
        id: '1-1-1',
        title: '4-5月抢好胎送豪礼',
        active: false
      }
    }]
  },
  // product,
  order,
  // sales,
  // manage,
  // welfare,
  // policy,
  // report,
  // operation,
  company,
  setting,
  source,
  {
    path: '/login',
    name: 'login',
    hidden: true, // 左侧菜单隐藏
    component: resolve => require(['@/views/Login'], resolve),
    meta: {
      title: '登录'
    }
  }, {
    path: '*',
    hidden: true,
    component: resolve => require(['@/views/home/404'], resolve)
  },
  {
    path: '/refuse',
    name: 'refuse',
    hidden: true,
    component: resolve => require(['@/views/home/Refuse'], resolve),
    meta: {
      title: '拒绝登录'
    }
  }, {
    path: '/disabled',
    name: 'disabled',
    hidden: true,
    component: resolve => require(['@/views/home/Disabled'], resolve),
    meta: {
      title: '用户禁用'
    }
  }, {
    path: '/test/interface',
    name: 'interface',
    hidden: true,
    component: resolve => require(['@/views/home/Interface'], resolve),
    meta: {
      title: '接口测试'
    }
  }
  // {
  //   path: '/demo',
  //   component: resolve => require(['@/views/home/Demo'], resolve),
  // }
  ]
})

iview.LoadingBar.config({
  color: 'yellowgreen',
  failedColor: '#f06',
  height: 5
})

router.beforeEach((to, from, next) => {
  iview.LoadingBar.start()
  if (to.name === 'base') {
    next({ path: '/home/platform/list' })
    iview.LoadingBar.finish()
  } else {
    next()
  }
})

router.afterEach((to, from, next) => {
  iview.LoadingBar.finish()
})

export default router
